package com.visikard.asynctask;

import android.os.Handler;
import android.os.Message;

import com.visikard.application.UIMessage;
import com.visikard.business.CouponBUS;
import com.visikard.response.BaseResponse;
import com.visikard.response.DeleteCouponBuilderResponse;

public class DeleteCouponTask extends BaseTask {

	public static final int POS_UID = 0;
	public static final int POS_FKUSER = 1;
	public static final int POS_ID = 2;
	private long mDeletedId;

	public DeleteCouponTask(Handler handler) {
		super(handler);
	}

	public DeleteCouponTask(Handler handler, boolean isShowProgress) {
		super(handler, isShowProgress);
	}

	@Override
	protected Object doBackgroundWork(Object... params) {

		long uid = (Long) params[POS_UID];
		long fkUser = (Long) params[POS_FKUSER];
		long id = (Long) params[POS_ID];

		mDeletedId = id;

		CouponBUS busObj = new CouponBUS();
		return busObj.deleteCouponsBuilder(uid, fkUser, id);
	}

	@Override
	protected boolean handleResult(Object result) {
		DeleteCouponBuilderResponse response = (DeleteCouponBuilderResponse) result;
		if (result != null) {
			switch (response.getErrorCode()) {
				case BaseResponse.SUCCESS:
					if (response.getMessage().equals("SUCCESS") || response.getMessage().equals("Success")) {
						Message msg = new Message();
						msg.obj = mDeletedId;
						msg.what = UIMessage.MSG_DELETE_COUPONS_SUCCESS;
						mUIHandler.sendMessage(msg);
					}
					else {
						mUIHandler.sendEmptyMessage(UIMessage.MSG_DELETE_COUPONS_FAILED);
					}
					return true;
			}
		}
		return false;
	}

}
